home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d20 / msgq160s.arc / MAINTMSG.C < prev    next >
Text File  |  1991-10-26  |  5KB  |  250 lines

  1. /*
  2.  * MAINTMSG.C - Message maintenance
  3.  *
  4.  * Msged/Q message editor for QuickBBS  Copyright 1990 by P.J. Muller
  5.  *
  6.  */
  7.  
  8. #define TEXTLEN 200
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13.  
  14. #include "msged.h"
  15. #include "screen.h"
  16. #include "qmsgbase.h"
  17.  
  18. static int menu(void);
  19. static BOOLEAN copyto(BOOLEAN show);
  20. static BOOLEAN forward(void);
  21.  
  22. /*
  23.  * Show little menu at top
  24.  */
  25.  
  26. static int menu()
  27. {
  28.   int ch;
  29.  
  30.   gotoxy(9, 1);
  31.   clreol();
  32.   set_color(co_hilite);
  33.   bputc('M');
  34.   set_color(co_normal);
  35.   bputs("ove / ");
  36.   set_color(co_hilite);
  37.   bputc('C');
  38.   set_color(co_normal);
  39.   bputs("opy / Copy and ");
  40.   set_color(co_hilite);
  41.   bputc('S');
  42.   set_color(co_normal);
  43.   bputs("how or ");
  44.   set_color(co_hilite);
  45.   bputc('F');
  46.   set_color(co_normal);
  47.   bputs("orward this message? ");
  48.   video_update();
  49.   ch = getkey() & 0x7f;
  50.   ch = tolower(ch);       /* some tolower() implementations
  51.                  evaluate the argument twice (msc) */
  52.   bputc((char) ch);
  53.  
  54.   return(ch);
  55. } /* menu */
  56.  
  57. void movemsg()
  58. {
  59.   int tmp;
  60.  
  61.   for (;;) {
  62.     switch (menu()) {
  63.  
  64.       case 'c':    (void)copyto(FALSE);
  65.         return;
  66.  
  67.       case 's': (void)copyto(TRUE);
  68.         return;
  69.  
  70.       case 'm':    tmp = curmsg(CurBoard);
  71.         if (copyto(FALSE))
  72.           msgdelete(tmp,arealist[area].echomail,arealist[area].netmail);
  73.         return;
  74.  
  75.       case 'f':    (void)forward();
  76.         return;
  77.  
  78.       case 27:    return;        /* escape */
  79.  
  80.     } /* switch */
  81.   } /* forever */
  82. } /* movemsg */
  83.  
  84. /*
  85.  * Copy the current message to another board
  86.  * Reads over current message
  87.  * Returns TRUE if ok
  88.  */
  89.  
  90. static BOOLEAN copyto(BOOLEAN show)
  91. {
  92.   int keeparea = area, newarea;
  93.   BOOLEAN ok;
  94.  
  95.   newarea = selectarea("SELECT DESTINATION AREA");    /* destination area */
  96.   area = keeparea;    /* selectarea() might have changed it */
  97.   if (newarea == -1)
  98.     return FALSE;    /* not copied */
  99.  
  100.   if (!readmsg(&message, curmsg(CurBoard)))
  101.     return FALSE;
  102.  
  103. #ifdef EIDS
  104.   memset(&message.eid,0,sizeof(message.eid));
  105. #endif
  106.   memset(&message.msgid,0,sizeof(message.msgid));
  107.  
  108.   if (show) {
  109.     char org[TEXTLEN];
  110.  
  111.     sprintf(org, " * Copied from '%s' by %s\n",
  112.         arealist[area].description, username);
  113.     prependline("\n");
  114.     prependline(org);
  115.   } /* if */
  116.  
  117.   area = newarea;        /* new area */
  118.  
  119.   clear_attributes(&message.header);
  120.   message.header.msgnum = newmsgnum();
  121.   message.header.reply = message.header.up = 0;
  122.   message.header.board = CurBoard;
  123.  
  124.   ok = writemsg(&message);
  125.  
  126.   area = keeparea;
  127.  
  128.   return(ok);
  129. } /* copyto */
  130.  
  131. static BOOLEAN forward()
  132. {
  133.   char sfn[TEXTLEN];
  134.   char dfn[TEXTLEN];
  135.   char time[20], date[20];
  136.   int keeparea = area, newarea;
  137.   BOOLEAN ok;
  138.  
  139.   newarea = selectarea("SELECT DESTINATION AREA");    /* destination area */
  140.   area = keeparea;    /* restore it */
  141.   if (newarea == -1)
  142.     return TRUE;
  143.  
  144.   if (!readmsg(&message, curmsg(CurBoard)))
  145.     return FALSE;
  146.  
  147.   timestr(time,date);            /* get current time */
  148.   sprintf(sfn," * Original to %s @ %s\n", message.header.to,
  149.       formaddr(message.to,Z_A|N_A|P_O|D_O));
  150.   sprintf(dfn," * Forwarded %s by %s @ %s\n",
  151.       timedate(time, date, NO),
  152.       username,
  153.       formaddr(thisnode[arealist[newarea].aka],Z_A|N_A|P_O|D_O));
  154.  
  155.   area = newarea;
  156.  
  157.   clear_attributes(&message.header);    /* looks at current area */
  158.   message.header.msgnum = newmsgnum();
  159.   message.header.reply = message.header.up = 0;
  160.   message.header.board = CurBoard;
  161.  
  162.   prependline("\n");            /* forward header */
  163.   prependline(dfn);
  164.   prependline(sfn);
  165.  
  166.   editheader();        /* also resets eid */
  167.  
  168.   ok = writemsg(&message);
  169.  
  170.   area = keeparea;
  171.  
  172.   return(ok);
  173. } /* forward */
  174.  
  175. static char maintmenu(void)
  176. {
  177.   int ch;
  178.  
  179.   gotoxy(1, 1);  clreol();
  180.   bputs("Maintenance: ");
  181.   set_color(co_hilite);
  182.   bputc('D');
  183.   set_color(co_normal);
  184.   bputs("elete from current to last read in this area / ");
  185.   set_color(co_hilite);
  186.   bputs("Esc");
  187.   set_color(co_normal);
  188.   bputs(" to return: ");
  189.   video_update();
  190.   ch = getkey() & 0x7f;
  191.   ch = tolower(ch);       /* some tolower() implementations
  192.                  evaluate the argument twice (msc) */
  193.   bputc((char) ch);
  194.  
  195.   return(ch);
  196. } /* maintmenu */
  197.  
  198. static void delall(int delarea)
  199. {
  200.   int num, last;
  201.   BYTE board = arealist[delarea].board;
  202.  
  203.   scrollup(1,1,maxx,5,0);
  204.  
  205.   last = lastreadmsg(board);
  206.   num = curmsg(board);
  207.   if ((num <= 0) || (last <= 0)) return;
  208.  
  209.   gotoxy(3, 3);
  210.   set_color(co_warn);
  211.   bprintf("You are going to delete all messages from %d to %d in this area!",
  212.         num, last);
  213.   set_color(co_normal);
  214.  
  215.   if (!confirm(YES))
  216.     return;
  217.  
  218.   while ((num <= last) && (num > 0)) {
  219.     int next = msgnext(board, num);
  220.  
  221.     gotoxy(9,1);
  222.     bprintf("Deleting message %d", num);
  223.     clreol();
  224.  
  225.     if (keypressed())
  226.       if (getkey() == ABORT)
  227.     return;
  228.  
  229.     msgdelete(num,FALSE,FALSE);        /* don't update tosslogs */
  230.  
  231.     if (next == num) break;        /* reached end */
  232.     num = next;
  233.   } /* while */
  234.  
  235. } /* delall */
  236.  
  237. void maintarea()
  238. {
  239.   for (;;) {
  240.     switch (maintmenu()) {
  241.  
  242.       case 'd': delall(area);
  243.         return;
  244.  
  245.       case 27:    return;        /* escape */
  246.  
  247.     } /* switch */
  248.   } /* forever */
  249. } /* maintarea */
  250.